﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogFileConnector
{
    class FileFinder
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        public List<String> findFiles(String directory)
        {
            List<string> FileList = new List<string>();
            
            var files = from file in new System.IO.DirectoryInfo(directory).GetFiles()
                        where file.Extension.Equals(Configuration.fileExtension)
                        select file;
            foreach (System.IO.FileInfo filein in files.ToList())
            {
                FileList.Add(filein.FullName);
            }
            if (Configuration.searchSourceRecursive)
            {
                var dirs = from dir in new System.IO.DirectoryInfo(directory).GetDirectories()
                       select dir;
                foreach (System.IO.DirectoryInfo direc in dirs.ToList())
                {
                    FileList.AddRange(findFiles(direc.FullName));
                }
            }
            return FileList;
        }
    }
}
